import { mapGetters } from 'vuex'
export default {
  props: ['rowData'],
  data () {
    return {
      allPower: 0,
      companyList: [],
      loadingBtn: false,
      addRole: false
    }
  },
  computed: {
    ...mapGetters(['areaTree'])
  },
  methods: {
    addRoleClose () {
      this.addRole = false
      this.list.filter.pageNo = 1
      this.getList()
    },
    setDataPermStatus (status) {
      const loading = this.$loading({})
      this.$POST('sot-admin-api/sys/department/setDataPermStatus', {
        departmentId: this.rowData.departmentId,
        dataType: this.dataType,
        status
      })
        .then(res => {
          loading.close()
          if (res.errorCode == '00000') {
            this.$swal.success('设置成功')
          } else {
            this.allPower = status === 0 ? 1 : 0
            this.$swal.error(res.message)
          }
        })
        .catch(_ => {
          loading.close()
          this.allPower = status === 0 ? 1 : 0
        })
    },
    deleteDataPerm ({ id }) {
      this.loadingBtn = true
      this.$POST('sot-admin-api/sys/department/deleteDataPerm', {
        id,
        dataType: this.dataType
      })
        .then(res => {
          if (res.errorCode == '00000') {
            // 当只有一条且删除成功时，页面减一
            if (this.list.data.length == 1) {
              this.list.filter.pageNo--
            }
            this.getList()
          } else {
            this.$swal.error(res.message)
          }
        })
        .finally(_ => {
          this.loadingBtn = false
        })
    }
  },
  filters: {
    auditStatus (code) {
      const status = {
        0: '资料待审核',
        1: '待审核',
        2: '审核通过',
        3: '审核驳回'
      }
      return status[code] || ''
    }
  }
}
